package com.ckmike.product_service.service.impl;

import com.ckmike.product_service.domain.Product;
import com.ckmike.product_service.service.ProductService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ProductServiceImpl 简要描述
 * <p> TODO:描述该类职责 </p>
 *
 * @author ckmike
 * @version 1.0
 * @date 18-11-7 下午10:46
 * @copyright ckmike
 **/
@Service
public class ProductServiceImpl implements ProductService {
    private static Map<Integer, Product> daoMap = new HashMap();

    static {
        Product p1 = new Product(1, "iphoneX", 100, 9889d);
        Product p2 = new Product(2, "电脑", 100, 7889d);
        Product p3 = new Product(3, "洗衣机", 100, 1889d);
        Product p4 = new Product(4, "手表", 100, 9089d);
        Product p5 = new Product(5, "汽车", 100, 119889d);
        Product p6 = new Product(6, "面包机", 100, 989d);
        Product p7 = new Product(7, "雨伞", 100, 98.89d);
        Product p8 = new Product(8, "鞋子", 100, 988d);
        daoMap.put(p1.getId(), p1);
        daoMap.put(p2.getId(), p2);
        daoMap.put(p3.getId(), p3);
        daoMap.put(p4.getId(), p4);
        daoMap.put(p5.getId(), p5);
        daoMap.put(p6.getId(), p6);
        daoMap.put(p7.getId(), p7);
        daoMap.put(p8.getId(), p8);
    }

    @Override
    public List<Product> listProduct() {
        return new ArrayList<>(daoMap.values());
    }

    @Override
    public Product findById(int id) {
        return daoMap.get(id);
    }
}
